package com.rxyl.love.petdoctor.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rxyl.love.petdoctor.R;

/**
 * Created by Administrator on 2016/1/11 0011.
 */
public class SelectItemsView extends LinearLayout {
    private ImageView iv_icon;
    private TextView  tv_title;

    public SelectItemsView(Context context) {
        this(context, null);
    }

    public SelectItemsView(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.select_item_layout,this);
        iv_icon = (ImageView) findViewById(R.id.iv_item_icon);
        tv_title = (TextView) findViewById(R.id.tv_item_title);
        initAttribute(context, attrs);
    }

    private void initAttribute(Context context, AttributeSet attrs) {
       TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ItemSelector);

       Drawable icon = array.getDrawable(R.styleable.ItemSelector_item_icon);
        String title = array.getString(R.styleable.ItemSelector_item_title);
        iv_icon.setImageDrawable(icon);
        tv_title.setText(title);

        array.recycle();
    }

    /**
     * 设置条件
     * @param content
     */
    public void setContent(String content)
    {
        tv_title.setText(content);
    }

}
